﻿#region Using

using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration.Provider;

using SubjectWorkShop.Core;

#endregion

namespace SubjectWorkShop.Core.Providers
{           
    /// <summary>
    /// A base class for all custom providers to inherit from.
    /// </summary>
    public abstract partial class SubjectProvider : ProviderBase
    {

        #region Data Store
        // Data Store
        /// <summary>
        /// Loads settings from data store
        /// </summary>
        /// <param name="exType">Extension Type</param>
        /// <param name="exId">Extensio Id</param>
        /// <returns>Settings as stream</returns>
        public abstract object LoadFromDataStore(DataStore.ExtensionType exType, string exId);
        /// <summary>
        /// Saves settings to data store
        /// </summary>
        /// <param name="exType">Extension Type</param>
        /// <param name="exId">Extension Id</param>
        /// <param name="settings">Settings object</param>
        public abstract void SaveToDataStore(DataStore.ExtensionType exType, string exId, object settings);
        /// <summary>
        /// Removes settings from data store
        /// </summary>
        /// <param name="exType">Extension Type</param>
        /// <param name="exId">Extension Id</param>
        public abstract void RemoveFromDataStore(DataStore.ExtensionType exType, string exId);
        #endregion

        #region pages
        // Page
        /// <summary>
        /// Retrieves a Page from the provider based on the specified id.
        /// </summary>
        public abstract Page SelectPage(Guid id);
        /// <summary>
        /// Inserts a new Page into the data store specified by the provider.
        /// </summary>
        public abstract void InsertPage(Page page);
        /// <summary>
        /// Updates an existing Page in the data store specified by the provider.
        /// </summary>
        public abstract void UpdatePage(Page page);
        /// <summary>
        /// Deletes a Page from the data store specified by the provider.
        /// </summary>
        public abstract void DeletePage(Page page);
        /// <summary>
        /// Retrieves all Pages from the provider and returns them in a List.
        /// </summary>
        public abstract List<Page> FillPages();
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public abstract string StorageLocation();

        /// Settings
        /// <summary>
        /// Loads the settings from the provider.
        /// </summary>
        public abstract StringDictionary LoadSettings();
        /// <summary>
        /// Saves the settings to the provider.
        /// </summary>
        public abstract void SaveSettings(StringDictionary settings);
    }

    /// <summary>
    /// A collection of all registered providers.
    /// </summary>
    public class SubjectProviderCollection : ProviderCollection
    {
        /// <summary>
        /// Gets a provider by its name.
        /// </summary>
        public new SubjectProvider this[string name]
        {
            get { return (SubjectProvider)base[name]; }
        }

        /// <summary>
        /// Add a provider to the collection.
        /// </summary>
        public override void Add(ProviderBase provider)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            if (!(provider is SubjectProvider))
                throw new ArgumentException
                    ("Invalid provider type", "provider");

            base.Add(provider);
        }


    }


}
